package com.baor.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baor.dao.LogoDao;
import com.baor.domain.LogoVo;
import com.baor.domain.SeparateVo;
import com.baor.service.LogoService;
import com.baor.utils.AjaxResult;
import com.baor.utils.DateUtil;
import com.baor.utils.UploadUtil;
import com.netflix.discovery.converters.Auto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static com.baor.utils.DateUtil.now;


@Service
public class LogoServiceImpl implements LogoService {


    @Autowired
    private LogoDao logoDao;


    @Override
    public AjaxResult<?> logoList(Map<String, Object> params) {
        params.put("pageIndex", (int)params.get("pageSize") * ((int)(params.get("pageIndex")) - 1));
        params.put("pageSize", params.get("pageSize"));
        Map<String,Object> res = new HashMap<>();
        res.put("logoList",logoDao.logoList(params));
        res.put("pageCount",logoDao.pageCount(params));
        return AjaxResult.success(res);
    }

    @Override
    public AjaxResult<?> logoInfo(LogoVo logoVo) {
        LogoVo logoInfo = logoDao.selectById(logoVo.getLogoId());
        return AjaxResult.success(logoInfo);
    }

    @Override
    public AjaxResult<?> insertLogo(LogoVo logoVo) {
        logoVo.setCreateTime(DateUtil.now());
        int row = logoDao.insert(logoVo);
        if (row > 0) {
            return AjaxResult.success("添加成功");
        } else {
            return AjaxResult.error("添加失败");
        }
    }

    @Override
    public AjaxResult<?> updateLogo(LogoVo logoVo) {
        int row = logoDao.updateById(logoVo);
        if (row > 0) {
            return AjaxResult.success("更新成功");
        } else {
            return AjaxResult.error("更新失败");
        }
    }

    @Override
    public AjaxResult<?> deleteLogo(LogoVo logoVo) {
        logoVo.setDelFlag(1);
        int row = logoDao.updateById(logoVo);
        if (row > 0) {
            return AjaxResult.success("删除成功");
        } else {
            return AjaxResult.error("删除失败");
        }
    }

    @Override
    public AjaxResult<?> logoSelect(Integer siteId) {
        QueryWrapper<LogoVo> wrapper = new QueryWrapper<>();
        wrapper.eq("del_flag", 0).eq("site_id", siteId);
        return AjaxResult.success(logoDao.selectList(wrapper));
    }
}
